<html>
<head>
<title>ASP.NET Validation Controls</title>
<!-- #include file="style.inc" -->
</head>
<body bgcolor="#ffffff">
<!--------------------------------------------------------------------------->
<span class="heading">CustomValidator</span> &nbsp; &nbsp; &nbsp;
<form runat="server" action="getvalue.aspx" method="post">
 <table border="0">

<tr>
  <td valign="top">Number over 100</td>
  <td><input type="text" id="txtNumber" 
	maxlength="50" size="20" runat="server" />
	<asp:RequiredFieldValidator id="valRequired" runat="server"
          	 ControlToValidate="txtNumber"
          	 ErrorMessage="* You must enter a valid number over 100 (Require)"
          	 Display="dynamic">
          	 *
      </asp:RequiredFieldValidator><br />
      <asp:CompareValidator 
	id="valCompare" runat="server"             
	ControlToValidate="txtNumber"
	 ValueToCompare="100"
              Operator="GreaterThan"
	Type="Integer"
              ErrorMessage="* You must enter a valid number over 100 (Compare)"
               Display="dynamic">
             *
      </asp:CompareValidator> <br />
     <asp:CustomValidator id="valClientScript" runat="server"
           	ControlToValidate="txtNumber"      
	OnServerValidate="ServerValidate"
	ErrorMessage="* You must enter valid number over 100 (Custom)"
           	Display="dynamic">
           	Please enter valid number over 100.
      </asp:CustomValidator>
  </td>
 </tr>
 </table>

<asp:ValidationSummary id="valSummary" runat="server"
     HeaderText="<b>The following errors were found:</b>"
     ShowSummary="true" DisplayMode="List" />

<hr />
Validation Enabled:
<asp:DropDownList AutoPostBack="True" id="lstEnabled" runat="server">
<asp:ListItem Text="True" /><asp:ListItem Text="False" /></asp:DropDownList>
<p />&nbsp; &nbsp;
<input type="submit" id="cmdConfirm" value="Submit" runat="server" onserverclick="ConfirmEntry">&nbsp; &nbsp;
<input type="submit" id="cmdCancel" value="Cancel" runat="server" onserverclick="CancelEntry">&nbsp; &nbsp;
</form>
<div id="outMessage" EnableViewState="False" runat="server" />
<script language="VB" runat="server">

Sub Page_Load()

  Dim objValidator As BaseValidator
  For Each objValidator In Page.Validators
    objValidator.Enabled = lstEnabled.SelectedItem.Text   
    objValidator.EnableClientScript=False
  Next
  valSummary.ShowMessageBox = False
End Sub

Sub ServerValidate(objSource As Object, objArgs As ServerValidateEventArgs)
  Dim blnValid As Boolean = True
  Try
    Dim intNumber As Integer = objArgs.Value
    'check that it's an odd number
    If intNumber Mod 2 = 1 Then
      'get the largest possible divisor
      Dim intDivisor As Integer = intNumber \ 3
      If intDivisor > 2 Then
         Dim intLoop As Integer
         'check using each divisor in turn
         For intLoop = 3 To intDivisor Step 2
           If intNumber Mod intDivisor = 0 Then
             blnValid = False
             Exit For
           End If
         Next
      Else
        blnValid = False
      End If
    Else
      blnValid = False
    End If
  Catch objError As Exception
    blnValid =False
  Finally
    objArgs.IsValid = blnValid
  End Try
End Sub


Sub ConfirmEntry(objSender As Object, objArgs As EventArgs)
  outMessage.InnerHtml = "Page.IsValid returned <b>" & Page.IsValid & ".</b>"
End Sub

Sub CancelEntry(objSender As Object, objArgs As EventArgs)
  outMessage.InnerHtml = "Validation was not carried out."
End Sub

</script>
<!--------------------------------------------------------------------------->
<!-- #include file="foot.inc" -->
</body>
</html>

